package com.ronghui.cash.redisService;

import com.ronghui.cash.util.CodecUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.TimeUnit;

public class UserRedisService {

	@Autowired
	RedisTemplate<String,String> redisTemplate;
	public String getUserId(HttpServletRequest request){
		return redisTemplate.opsForValue().get("access:token:"+request.getParameter("token"));
	}
	
    /**
	 * 把token存在redis上
	 */
	public String setTokenOnRedis(String userId){
		   String token = CodecUtil.createUUID();
		   int exptime = 3600*24*30;//30天
		   redisTemplate.opsForValue().set("access:token:"+token,userId,exptime, TimeUnit.SECONDS);
		   return token;
	}
}
